// 云函数入口文件
const cloud = require('wx-server-sdk')
const db = cloud.database()
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  const getMaxNumber = () => {
    return Math.max(event.a, event.b)
  }

  const updateGoodsName = async () => {
    const res = await db.collection('hotList').where({
      goodsName: '山海经'
    }).update({
      data: {
        goodsName: event.goodsName
      }
    })

    return res
  }

  return {
    maxNumber: getMaxNumber(),
    updateGoodsName: updateGoodsName()
  }
}